home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / incl / LEDA / impl / gen_array.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  3.9 KB  |  149 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  gen_array.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef LEDA_GEN_ARRAY_H
  16. #define LEDA_GEN_ARRAY_H
  17.  
  18. //------------------------------------------------------------------------------
  19. // arrays
  20. //------------------------------------------------------------------------------
  21.  
  22. #include <LEDA/basic.h>
  23.  
  24.  
  25.  
  26. class gen_array {
  27.  
  28. protected:
  29.     GenPtr* v;
  30.     int sz;    
  31.         int Low;
  32.         int High;
  33.         int t;
  34.         int dir;
  35.  
  36.  
  37. virtual int cmp(GenPtr x, GenPtr y)           const { return compare(x,y); };
  38. virtual void print_el(GenPtr& x,ostream& out) const { Print(x,out); }
  39. virtual void read_el(GenPtr& x,istream& in)         { Read(x,in); }
  40. virtual void clear_entry(GenPtr&) {}
  41. virtual void copy_entry(GenPtr&)  {}
  42. virtual void init_entry(GenPtr&)  {}
  43.  
  44. virtual int  int_type() const { return 0; }
  45.  
  46.         void quick_sort(GenPtr*,GenPtr*);
  47.         void quick_sort(GenPtr*,GenPtr*,CMP_PTR);
  48.         void int_quick_sort(GenPtr*,GenPtr*);
  49.  
  50.         void insertion_sort(GenPtr*,GenPtr*,GenPtr*);
  51.         void insertion_sort(GenPtr*,GenPtr*,GenPtr*,CMP_PTR);
  52.         void int_insertion_sort(GenPtr*,GenPtr*,GenPtr*);
  53.  
  54.         void quick_test(GenPtr*,GenPtr*);
  55.  
  56. protected:
  57.         int  binary_search(GenPtr);
  58.         int  binary_search(GenPtr,CMP_PTR);
  59.         int  int_binary_search(GenPtr);
  60.  
  61.         void sort(int,int,CMP_PTR); 
  62.  
  63.  
  64.         void clear();
  65.  
  66. public:
  67.         void sort_test(int); 
  68.  
  69.         void init();
  70.         virtual ~gen_array() { if (v) delete[] v; }
  71.         gen_array();
  72.     gen_array(int);
  73.     gen_array(int, int);
  74.     gen_array(const gen_array&);
  75.     gen_array& operator=(const gen_array&);
  76.  
  77.         int      size() const     { return sz; }
  78.         int      low()  const     { return Low; }
  79.         int      high() const     { return High; }
  80.     GenPtr& elem(int i)       { return v[i]; }
  81.     GenPtr  elem(int i) const { return v[i]; }
  82.     GenPtr& entry(int i)
  83.     { if (i<Low || i>High)
  84.           error_handler(2,"array::entry index out of range");
  85.           return v[i-Low];
  86.          }
  87.     GenPtr  inf(int i) const
  88.     { if (i<Low || i>High)
  89.           error_handler(2,"array::inf index out of range");
  90.           return v[i-Low];
  91.          }
  92.  
  93.         void permute(int,int);
  94.         void permute()  { permute(Low,High); }
  95.  
  96.  
  97.    void print(ostream&,string, char space)   const;    
  98.    void print(ostream& out,char space=' ') const { print(out,"",space);  }
  99.    void print(string s, char space=' ')    const { print(cout,s,space);  }
  100.    void print(char space=' ')              const { print(cout,"",space); }   
  101.  
  102.  
  103.    void read(istream&,string);  
  104.    void read(istream& in)      { read(in,"");  }
  105.    void read(string s )        { read(cin,s);  }   
  106.    void read()                 { read(cin,""); }   
  107.  
  108.  
  109. };
  110.  
  111.  
  112. /*------------------------------------------------------------------------*/
  113. /* 2 dimensional arrays                                                   */
  114. /*------------------------------------------------------------------------*/
  115.  
  116.  
  117. class gen_array2 {
  118. gen_array A;
  119. int Low1, Low2, High1, High2;
  120. virtual void clear_entry(GenPtr& x)  { x = 0; }
  121. virtual void copy_entry(GenPtr& x)   { x = 0; }
  122. virtual void init_entry(GenPtr& x)   { x = 0; }
  123.  
  124. protected:
  125. void clear();
  126. gen_array* row(int i) const { return (gen_array*)A.inf(i); }
  127.  
  128. public:
  129. void init(int,int,int,int);
  130. int low1()  { return Low1; }
  131. int low2()  { return Low2; }
  132. int high1() { return High1; }
  133. int high2() { return High2; }
  134. gen_array2(int,int,int,int);
  135. gen_array2(int,int);
  136. virtual ~gen_array2();
  137. };
  138.  
  139.  
  140.  
  141. // default I/O and cmp functions
  142.  
  143. inline void Print(const gen_array& A, ostream& out) { A.print(out); }
  144. inline void Read(gen_array& A, istream& in) { A.read(in); }
  145. inline int compare(const gen_array&,const gen_array&) { return 0; }
  146.  
  147. #endif
  148.